package tp.pr2;

//import java.util.List;

public class Room
{

	private boolean exit;
	private String description;

	private ItemList listaItems;

	
	public Room(boolean exit, String description)
	{
		this.exit=exit;
		this.description=description;
		this.listaItems=new ItemList();
	}

	public Room(boolean exit, String description, Item[] items)
	{
		this.exit=exit;
		this.description=description;
		this.listaItems=new ItemList(items);
	}

	public boolean isExit()
	{
		boolean salida = this.exit;

		return salida;
	}


		public String getDescription(){
			String lista=this.listaItems.toString();
			String desc;
			if(lista==null)
			return(this.description+"\nThis room is empty");

			desc=this.description+"\n"+"It contains the following items:\n"+lista;
			return  desc;//this.listaItems.toString();
				
		}



	public boolean addItem(Item it)
	{
		return this.listaItems.add(it);
	}

	public boolean pickItem(Player who, String id)
	{
		int posicion = this.listaItems.searchItem(id);
		if (posicion == -1)
			return false;
		Item item = this.listaItems.get(posicion);
		if (who.addItem(item))
		{
			this.listaItems.remove(posicion);// "remove" no borra, sólo quita la
														// referencia.
			return true;
		}
		return false;
	}

	public boolean existsItem(String id)
	{

		return (this.listaItems.searchItem(id) != -1);
	}
}
